﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Monitor.Models.Json
{
    public class UserRow
    {
        public string Login { get; set; }
        public string Name { get; set; }
        public string Family { get; set; }
        public string Role { get; set; }
        public Int64 CountOfCar { get; set; } 
    }

    public class UserModel
    {
        public string Login { get; set; }
        public string Name { get; set; }
        public string Family { get; set; }
        public string Role { get; set; }
        public ClassifElement Service { get; set; }
        public IEnumerable<ClassifElement> CarList { get; set; } 
    }
    public class ClassifElement
    {
        public Int64 Id { get; set; }
        [IgnoreDataMember]
        public Int64 HidenId { get; set; }
        public string Name { get; set; }
        public string Comment { get; set; }
    }
    public class UserInputModel
    {
        public bool IsNewUser { get; set; }
        public string Login { get; set; }
        public string Password { get; set; }
        public string UserName { get; set; }
        public string Family { get; set; }
        public string Role { get; set; }
        public Int64 DilerId { get; set; }
        public IEnumerable<Int64> ListOfCar { get; set; } 
        public bool IsValid
        {
            get
            {
                if (IsNewUser)
                {
                    return !(string.IsNullOrWhiteSpace(Login) ||
                             string.IsNullOrWhiteSpace(Password) ||
                             string.IsNullOrWhiteSpace(UserName) ||
                             string.IsNullOrWhiteSpace(Family) ||
                             string.IsNullOrWhiteSpace(Role) ||
                             (DilerId == 0) ||
                             (ListOfCar == null) ||
                             (!ListOfCar.Any()));
                }
                else
                {
                    return !(string.IsNullOrWhiteSpace(Login) ||
                             string.IsNullOrWhiteSpace(UserName) ||
                             string.IsNullOrWhiteSpace(Family) ||
                             string.IsNullOrWhiteSpace(Role) ||
                             (DilerId == 0) ||
                             (ListOfCar == null) ||
                             (!ListOfCar.Any()));
                }
            }
        }
    }
}